<?php
function safesql($theValue, $theType, $striptags = true, $theDefinedValue = "", $theNotDefinedValue = "") 
{
    $theValue = $striptags ? strip_tags($theValue) : $theValue;
    $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$dbconnection = mysql_connect("localhost", "wtfsza_cmscout", "cm*scout234") or die(mysql_error());
$selectedb = mysql_select_db("wtfsza_cmscout") or die(mysql_error());

$name = safesql(urldecode($_GET['troopname']), "text");
$address = safesql(urldecode($_GET['address']), "text");
$version = safesql($_GET['version'], "text");
if (isset($name) && isset($address) && isset($version))
{
    $timenow = time();
    $sql = mysql_query("SELECT name FROM cms_installedsites WHERE address=$address") or die(mysql_error());
    if (mysql_num_rows($sql) == 0)
    {
        mysql_query("INSERT INTO cms_installedsites VALUES ('', $name, $address, $version, $timenow, 1)") or die(mysql_error());
    }
    else
    {
        mysql_query("UPDATE cms_installedsites SET date=$timenow, version=$version, name=$name, active=1 WHERE address=$address") or die(mysql_error());
    }
}
?>